<template>
	<view class="fee-selector" v-if="show">
		<view class="mask" @tap="cancel"></view>
		<view class="content">
			<!-- 顶部操作栏 -->
			<view class="header">
				<text class="cancel" @tap="cancel">取消</text>
				<text class="title">收费方式</text>
				<text class="confirm" @tap="confirm">确定</text>
			</view>

			<!-- 收费类型列表 -->
			<view class="fee-list">
				<view class="fee-item" 
					v-for="(item, index) in feeTypes" 
					:key="index"
					:class="{ 'selected': selectedType === item.dictValue }"
					@tap="selectType(item)"
				>
					<view class="fee-info">
						<text class="fee-name">{{ item.dictLabel }}</text>
						<text class="fee-desc" v-if="item.remark">{{ item.remark }}</text>
					</view>
					<text class="check-icon" v-if="selectedType === item.dictValue">✓</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { listSportType } from '@/api/youqiu/activity.js'

export default {
	name: 'FeeTypeSelector',
	props: {
		show: {
			type: Boolean,
			default: false
		},
		value: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			selectedType: '',
			feeTypes: []
		}
	},
	watch: {
		show(newVal) {
			if (newVal) {
				this.getFeeTypes()
				if (this.value) {
					this.selectedType = this.value
				}
			}
		},
		value(newVal) {
			this.selectedType = newVal
		}
	},
	methods: {
		// 获取收费类型列表
		getFeeTypes() {
			listSportType('sys_fee_type').then(res => {
				console.log('收费类型列表：', res)
				this.feeTypes = res.data
			}).catch(err => {
				console.error('获取收费类型失败：', err)
				uni.showToast({
					title: '获取收费类型失败',
					icon: 'none'
				})
			})
		},
		selectType(type) {
			this.selectedType = type.dictValue
		},
		cancel() {
			this.$emit('update:show', false)
		},
		confirm() {
			const selectedFeeType = this.feeTypes.find(item => item.dictValue === this.selectedType)
			if (selectedFeeType) {
				this.$emit('select', selectedFeeType)
				this.$emit('input', selectedFeeType.dictValue)
			}
			this.$emit('update:show', false)
		}
	}
}
</script>

<style lang="scss" scoped>
.fee-selector {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 999;

	.mask {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.4);
	}

	.content {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		background: #fff;
		border-radius: 20rpx 20rpx 0 0;
		transform: translateY(0);

		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 30rpx;
			border-bottom: 1px solid #eee;

			.cancel {
				color: #666;
			}

			.title {
				font-weight: bold;
			}

			.confirm {
				color: #ff6b6b;
			}
		}

		.fee-list {
			max-height: 600rpx;
			overflow-y: auto;

			.fee-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx 20rpx;
				border-bottom: 1px solid #eee;

				.fee-info {
					flex: 1;

					.fee-name {
						font-size: 28rpx;
						color: #333;
						margin-bottom: 10rpx;
						display: block;
					}

					.fee-desc {
						font-size: 24rpx;
						color: #999;
					}
				}

				.check-icon {
					color: #07C160;
					font-size: 40rpx;
					margin-left: 20rpx;
				}

				&.selected {
					background-color: #f8f8f8;
				}

				&:active {
					background-color: #f0f0f0;
				}
			}
		}
	}
}
</style> 